package ru.spbau.bytecode.graph;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;

import java.awt.Color;

import org.junit.Test;

import ru.spbau.bytecode.graph.Edge;
import ru.spbau.bytecode.graph.Vertex;

public class EdgeTest {
	
	private final String firstSourceVertexName = "v1";
	private final String firstTargetVertexName = "u1";
	private final String secondSourceVertexName = "v2";
	private final String secondTargetVertexName = "u2";
	
	private final Vertex v1 = new Vertex(firstSourceVertexName);
	private final Vertex u1 = new Vertex(firstTargetVertexName);
	private final Edge e1 = new Edge(v1, u1);

	@Test
	public void testGetSourseVertex() {
		assertEquals(v1, e1.getSourceVertex());
	}
	
	@Test
	public void testGetTargetVertex() {
		assertEquals(u1, e1.getTargetVertex());
	}
	
	@Test
	public void testEquals() {
		Vertex v2 = new Vertex(firstSourceVertexName);
		Vertex u2 = new Vertex(firstTargetVertexName);
		Edge e2 = new Edge(v2, u2);
		
		assertEquals(e1, e2);
	}
	
	@Test
	public void testNotEquals1() {
		Vertex u1 = new Vertex(secondSourceVertexName);
		Vertex u2 = new Vertex(secondTargetVertexName);
		Edge e2 = new Edge(u1, u2);
		
		assertFalse(e1.equals(e2));
	}
	
	@Test
	public void testNotEquals2() {
		Vertex u1 = new Vertex(firstSourceVertexName);
		Vertex u2 = new Vertex(secondTargetVertexName);
		Edge e2 = new Edge(u1, u2);
		
		assertFalse(e1.equals(e2));
	}
	
	@Test
	public void testNotEquals3() {
		Vertex u1 = new Vertex(secondSourceVertexName);
		Vertex u2 = new Vertex(firstTargetVertexName);
		Edge e2 = new Edge(u1, u2);
		
		assertFalse(e1.equals(e2));
	}
	
	@Test
	public void testNotEquals4() {
		assertFalse(e1.equals(v1));
	}
	
	@Test
	public void testHashCode() {
		int expected = ('v' * 31 + '1') * 13 + ('u' * 31 + '1') * 31;
		assertEquals(expected, e1.hashCode());
	}
	
	@Test
	public void testGetColor() {
		Color color = Color.BLACK;
		e1.setColor(color);
		assertEquals(color, e1.getColor());
	}
	
	
}
